package cn.wolfcode.luowowo.mgrsite.persistence;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.ArticleStrategyStatisVO;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisVOService;
import cn.wolfcode.luowowo.cache.util.RedisKeysUtil;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

//@Component //先不开
public class RedisDatePersistence {

    @Reference
    private IStrategyStatisVOService strategyStatisVOService;
    @Reference
    private IStrategyDetailService strategyDetailService;
    /**
     *  Seconds Minutes Hours DayofMonth Month DayofWeek Year
     *
     *　Seconds Minutes Hours DayofMonth Month DayofWeek(spring支持)
     */
    @Scheduled(cron="0/120 * * * * ? ")//每20秒执行一次
    public void dowork(){
        System.err.println("------------Redis持久化开始--------------");
        //设计key值
        String key = RedisKeysUtil.STRATEGY_STATIS_VO.join("*");
        List<StrategyStatisVO> vos = strategyStatisVOService.getDetailRedisDates(key);
        for (StrategyStatisVO vo : vos) {
            ArticleStrategyStatisVO avo = new ArticleStrategyStatisVO();
            BeanUtils.copyProperties(vo,avo);
            strategyDetailService.persistenceDate(avo);
        }

        System.err.println("------------Redis持久化结束--------------");
    }
}
